package com.cy.notice.web.controller;

import com.cy.pj.common.util.PageUtil;
import com.cy.pj.notice.web.pojo.TesResult;
import com.cy.pj.sys.pojo.SysNotice;
import com.cy.pj.sys.service.SysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/notice/")
public class SysNoticeController {
    @Autowired
    private SysNoticeService sysNoticeService;

    @GetMapping
    public TesResult doFindNotices(SysNotice SysNotice){
        /*PageInfo<SysNotice> pageInfo = PageHelper.startPage(1,3)
                .doSelectPageInfo(new ISelect() {
                    @Override
                    public void doSelect() {
                        sysNoticeService.findNotices(SysNotice);
                    }
                });*/
        return new TesResult(PageUtil.startPage().doSelectPageInfo(()->sysNoticeService.findNotices(SysNotice)));
        /*return new TesResult(PageHelper.startPage(1,3)
                .doSelectPageInfo(()->sysNoticeService.findNotices(SysNotice)));*/
        //return new TesResult(sysNoticeService.findNotices(SysNotice));
    }

    @PostMapping
    public TesResult doSaveNotice(@RequestBody SysNotice notice){
        sysNoticeService.saveNotice(notice);
        return new TesResult("save ok");
    }

    @GetMapping("{id}")
    public TesResult doFindById(@PathVariable Long id){
        return new TesResult(sysNoticeService.findById(id));
    }

    @PutMapping
    public TesResult doUpdataNotice(@RequestBody SysNotice notice){
        sysNoticeService.updateNotice(notice);
        return new TesResult("updata ok");
    }

    @DeleteMapping("{id}")
    public TesResult doDeleteById(@PathVariable Long... id){
        sysNoticeService.deleteById(id);
        return new TesResult("delete ok");
    }
}
